home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2014 August / PCgo_CD_2014-08.iso / nw.pak / Unnamed File 000844.txt < prev    next >
Encoding:
Text File  |  2012-12-14  |  3.4 KB  |  94 lines

  1. // Copyright (c) 2012 Intel Corp
  2. // Copyright (c) 2012 The Chromium Authors
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. //  in the Software without restriction, including without limitation the rights
  7. //  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
  8. // pies of the Software, and to permit persons to whom the Software is furnished
  9. //  to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in al
  12. // l copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
  15. // PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
  16. // S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  17. //  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
  18. // ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  
  21. var nwDispatcher = nwDispatcher || {};
  22.  
  23. (function() {
  24.   native function RequireNwGui();
  25.   native function GetAbsolutePath();
  26.  
  27.   native function GetShellIdForCurrentContext();
  28.   native function GetRoutingIDForCurrentContext();
  29.   native function CreateShell();
  30.  
  31.   native function AllocateObject();
  32.   native function DeallocateObject();
  33.   native function CallObjectMethod();
  34.   native function CallObjectMethodSync();
  35.   native function CallStaticMethod();
  36.   native function CallStaticMethodSync();
  37.  
  38.   nwDispatcher.requireNwGui = RequireNwGui;
  39.  
  40.   // Request a new object from browser
  41.   nwDispatcher.allocateObject = function(object, option) {
  42.     var v8_util = process.binding('v8_util');
  43.  
  44.     var id = global.__nwObjectsRegistry.allocateId();
  45.     AllocateObject(id, v8_util.getConstructorName(object), option);
  46.  
  47.     // Store object id and make it readonly
  48.     Object.defineProperty(object, 'id', {
  49.       value: id,
  50.       writable: false
  51.     });
  52.  
  53.     // Deallcoate on destroy
  54.     v8_util.setDestructor(object, nwDispatcher.deallocateObject);
  55.  
  56.     // Store id to object relations, there is no delete in deallocateObject
  57.     // since this is a weak map.
  58.     global.__nwObjectsRegistry.set(id, object);
  59.   }
  60.  
  61.   // Free a object in browser
  62.   nwDispatcher.deallocateObject = function(object) {
  63.     DeallocateObject(object.id);
  64.   };
  65.  
  66.   // Call method of a object in browser.
  67.   nwDispatcher.callObjectMethod = function(object, method, args) {
  68.     CallObjectMethod(object.id,
  69.                      process.binding('v8_util').getConstructorName(object),
  70.                      method,
  71.                      args);
  72.   };
  73.  
  74.   // Call sync method of a object in browser and return results.
  75.   nwDispatcher.callObjectMethodSync = function(object, method, args) {
  76.     return CallObjectMethodSync(
  77.         object.id,
  78.         process.binding('v8_util').getConstructorName(object),
  79.         method,
  80.         args);
  81.   };
  82.  
  83.   // Call a static method.
  84.   nwDispatcher.callStaticMethod = CallStaticMethod;
  85.  
  86.   // Call a sync method of static class in browse and return.
  87.   nwDispatcher.callStaticMethodSync = CallStaticMethodSync;
  88.  
  89.   nwDispatcher.getAbsolutePath = GetAbsolutePath;
  90.   nwDispatcher.getShellIdForCurrentContext = GetShellIdForCurrentContext;
  91.   nwDispatcher.getRoutingIDForCurrentContext = GetRoutingIDForCurrentContext;
  92.   nwDispatcher.createShell = CreateShell;
  93. })();
  94.